﻿/**  版本信息模板在安装目录下，可自行修改。
* view_order.cs
*
* 功 能： N/A
* 类 名： view_order
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/8/14 21:21:43   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Yd.Domain.DAL;
//using Maticsoft.DBUtility;//Please add references
namespace Yd.DAL
{
	/// <summary>
	/// 数据访问类:view_order
	/// </summary>
	public partial class view_order
	{
		public view_order()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Yd.Model.view_order model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into view_order(");
			strSql.Append("oid,orderno,shopid,suid,shopName,kzName,total,createTime,arrivalTime,orderStatus,userName)");
			strSql.Append(" values (");
			strSql.Append("@oid,@orderno,@shopid,@suid,@shopName,@kzName,@total,@createTime,@arrivalTime,@orderStatus,@userName)");
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4),
					new SqlParameter("@orderno", SqlDbType.VarChar,35),
					new SqlParameter("@shopid", SqlDbType.Int,4),
					new SqlParameter("@suid", SqlDbType.Int,4),
					new SqlParameter("@shopName", SqlDbType.NVarChar,250),
					new SqlParameter("@kzName", SqlDbType.NVarChar,250),
					new SqlParameter("@total", SqlDbType.Decimal,9),
					new SqlParameter("@createTime", SqlDbType.DateTime),
					new SqlParameter("@arrivalTime", SqlDbType.NVarChar,250),
					new SqlParameter("@orderStatus", SqlDbType.Int,4),
					new SqlParameter("@userName", SqlDbType.NVarChar,100)};
			parameters[0].Value = model.oid;
			parameters[1].Value = model.orderno;
			parameters[2].Value = model.shopid;
			parameters[3].Value = model.suid;
			parameters[4].Value = model.shopName;
			parameters[5].Value = model.kzName;
			parameters[6].Value = model.total;
			parameters[7].Value = model.createTime;
			parameters[8].Value = model.arrivalTime;
			parameters[9].Value = model.orderStatus;
			parameters[10].Value = model.userName;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Yd.Model.view_order model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update view_order set ");
			strSql.Append("oid=@oid,");
			strSql.Append("orderno=@orderno,");
			strSql.Append("shopid=@shopid,");
			strSql.Append("suid=@suid,");
			strSql.Append("shopName=@shopName,");
			strSql.Append("kzName=@kzName,");
			strSql.Append("total=@total,");
			strSql.Append("createTime=@createTime,");
			strSql.Append("arrivalTime=@arrivalTime,");
			strSql.Append("orderStatus=@orderStatus,");
			strSql.Append("userName=@userName");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
					new SqlParameter("@oid", SqlDbType.Int,4),
					new SqlParameter("@orderno", SqlDbType.VarChar,35),
					new SqlParameter("@shopid", SqlDbType.Int,4),
					new SqlParameter("@suid", SqlDbType.Int,4),
					new SqlParameter("@shopName", SqlDbType.NVarChar,250),
					new SqlParameter("@kzName", SqlDbType.NVarChar,250),
					new SqlParameter("@total", SqlDbType.Decimal,9),
					new SqlParameter("@createTime", SqlDbType.DateTime),
					new SqlParameter("@arrivalTime", SqlDbType.NVarChar,250),
					new SqlParameter("@orderStatus", SqlDbType.Int,4),
					new SqlParameter("@userName", SqlDbType.NVarChar,100)};
			parameters[0].Value = model.oid;
			parameters[1].Value = model.orderno;
			parameters[2].Value = model.shopid;
			parameters[3].Value = model.suid;
			parameters[4].Value = model.shopName;
			parameters[5].Value = model.kzName;
			parameters[6].Value = model.total;
			parameters[7].Value = model.createTime;
			parameters[8].Value = model.arrivalTime;
			parameters[9].Value = model.orderStatus;
			parameters[10].Value = model.userName;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from view_order ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Yd.Model.view_order GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 oid,orderno,shopid,suid,shopName,kzName,total,createTime,arrivalTime,orderStatus,userName from view_order ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			Yd.Model.view_order model=new Yd.Model.view_order();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Yd.Model.view_order DataRowToModel(DataRow row)
		{
			Yd.Model.view_order model=new Yd.Model.view_order();
			if (row != null)
			{
				if(row["oid"]!=null && row["oid"].ToString()!="")
				{
					model.oid=int.Parse(row["oid"].ToString());
				}
				if(row["orderno"]!=null)
				{
					model.orderno=row["orderno"].ToString();
				}
				if(row["shopid"]!=null && row["shopid"].ToString()!="")
				{
					model.shopid=int.Parse(row["shopid"].ToString());
				}
				if(row["suid"]!=null && row["suid"].ToString()!="")
				{
					model.suid=int.Parse(row["suid"].ToString());
				}
				if(row["shopName"]!=null)
				{
					model.shopName=row["shopName"].ToString();
				}
				if(row["kzName"]!=null)
				{
					model.kzName=row["kzName"].ToString();
				}
				if(row["total"]!=null && row["total"].ToString()!="")
				{
					model.total=decimal.Parse(row["total"].ToString());
				}
				if(row["createTime"]!=null && row["createTime"].ToString()!="")
				{
					model.createTime=DateTime.Parse(row["createTime"].ToString());
				}
				if(row["arrivalTime"]!=null)
				{
					model.arrivalTime=row["arrivalTime"].ToString();
				}
				if(row["orderStatus"]!=null && row["orderStatus"].ToString()!="")
				{
					model.orderStatus=int.Parse(row["orderStatus"].ToString());
				}
				if(row["userName"]!=null)
				{
					model.userName=row["userName"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select oid,orderno,shopid,suid,shopName,kzName,total,createTime,arrivalTime,orderStatus,userName ");
			strSql.Append(" FROM view_order ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" oid,orderno,shopid,suid,shopName,kzName,total,createTime,arrivalTime,orderStatus,userName ");
			strSql.Append(" FROM view_order ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM view_order ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.uid desc");
			}
			strSql.Append(")AS Row, T.*  from view_order T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "view_order";
			parameters[1].Value = "uid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

